<template>
  <q-layout view="lHh Lpr lFf">
    <q-header elevated>
      <q-toolbar>
        <q-btn flat dense round icon="mdi-arrow-left" aria-label="Back"
               v-if="$route.meta && $route.meta.previous" @click="goPrevious" />

        <q-toolbar-title>
          Saltybe Estate
        </q-toolbar-title>
      </q-toolbar>
    </q-header>

    <q-page-container>
      <router-view />
    </q-page-container>
  </q-layout>
</template>

<script lang="ts">
import { defineComponent } from '@vue/composition-api';

export default defineComponent({
  name: 'MainLayout',
  setup() {
    return {};
  },
  methods: {
    goPrevious(): void {
      const previous: string | null = this.$route.meta?.previous;
      if (!previous) return;
      this.$router.push(previous).catch(() => {
        document.location = previous as unknown as Location
      });
    }
  }
});
</script>
